package com.zhongjian.technologycal.mall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zhongjian.technologycal.mall.R;
import com.zhongjian.technologycal.mall.base.BaseContacts;
import com.zhongjian.technologycal.mall.bean.FansBeans;

import java.util.List;

/**
 * Created by wei on 2018/1/17.
 */

public class FansListAdaper extends BaseAdapter {
    private Context context;
    private List<FansBeans> listItems;
    private LayoutInflater listContainer;

    public FansListAdaper(Context context, List<FansBeans> listItems) {
        this.context = context;
        listContainer = LayoutInflater.from(context);
        this.listItems = listItems;
    }

    @Override
    public int getCount() {
        return listItems.size();
    }

    @Override
    public Object getItem(int position) {
        return listItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ListItemView listItemView = null;
        if (convertView == null) {
            listItemView = new ListItemView();
            convertView = listContainer.inflate(R.layout.items_fans_list,
                    null);
            listItemView.fans_iv_img = (ImageView) convertView
                    .findViewById(R.id.fans_iv_img);
            listItemView.fans_tv_title_name = (TextView) convertView
                    .findViewById(R.id.fans_tv_title_name);
            listItemView.fans_tv_userId = (TextView) convertView
                    .findViewById(R.id.fans_tv_userId);
            listItemView.fans_tv_money = (TextView) convertView
                    .findViewById(R.id.fans_tv_money);
            convertView.setTag(listItemView);
        } else {
            listItemView = (ListItemView) convertView.getTag();
        }

        //将数据填充到具体的view中
        String phone = listItems.get(position).getUserName();
//        String telPhone = phone.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
        listItemView.fans_tv_title_name.setText("" + phone);
        listItemView.fans_tv_userId.setText("众健ID:" + listItems.get(position).getSysID());
        Picasso.get()
                .load(BaseContacts.BASE_URL +
                        listItems.get(position).getHeadPhoto())
                .into(listItemView.fans_iv_img);
        listItemView.fans_tv_money.setText("" + listItems.get(position).getAmount());

        return convertView;
    }

    public final class ListItemView {
        public ImageView fans_iv_img;
        public TextView fans_tv_title_name;
        public TextView fans_tv_userId;
        public TextView fans_tv_money;

    }


}
